﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DbAccess db = new DbAccess();
        //修改页面的标题
        this.Page.Title = "EShop在线购物商城";
        if (!Page.IsPostBack)
        {
            try
            {  
                ///绑定最新商品
                DataSet dsNew = db.GetDataSet("select top 4 * from Product order by ProId desc");
                DlNew.DataSource = dsNew.Tables[0].DefaultView;
                DlNew.DataBind();
                //绑定精品推荐
                DataSet dsRefine = db.GetDataSet("select top 4 * from Product where IsFaience=1 order by ProId desc");
                DlRefinement.DataSource = dsRefine.Tables[0].DefaultView;
                DlRefinement.DataBind();
                //绑定特价商品
                DataSet dsSale = db.GetDataSet("select top 4 * from Product where IsSale=1 order by ProId desc");
                DlSale.DataSource = dsSale.Tables[0].DefaultView;
                DlSale.DataBind();
            }
            catch(Exception ep)
            { 
            }    
        }
    }
    protected void buy(DataListCommandEventArgs e)
    {
        if (e.CommandName == "buy")
        {
            Session["Id"] = ((Label)e.Item.FindControl("Id")).Text;//商品编号
            Session["Proname"] = ((Label)e.Item.FindControl("Proname")).Text;//商品名称
            Session["MemberPrice"] = ((Label)e.Item.FindControl("MemberPrice")).Text;//商品单价
            Response.Redirect("Buy.aspx");
        }
    }
    protected void DlNew_ItemCommand(object source, DataListCommandEventArgs e)
    {
        buy(e);
    }
    protected void DlRefinement_ItemCommand(object source, DataListCommandEventArgs e)
    {
        buy(e);
    }
    protected void DlSale_ItemCommand(object source, DataListCommandEventArgs e)
    {
        buy(e);
    }
}
